/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2485.java
 * @Author : WangRuoyu
 * @Date 2023/1/30 9:47
 */

package leetcode;

public class Q2485 {
    public int pivotInteger(int n) {
        if (n == 1) {
            return 1;
        } else {
            int tmp = n;
            int sum = ((1 + n) * n) / 2;
            while ((sum + n) > tmp * 2) {
                n--;
                tmp += n;
            }
            if ((sum + n) == tmp * 2) {
                return n;
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) {
        Q2485 sl = new Q2485();
        int n = 8;
        for (int i = 0; i < 10; i++) {
            System.out.println(sl.pivotInteger(i));
        }
    }
}
